home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / speech recognition sample / speech recognition.doc < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.3 KB  |  84 lines

  1. /*
  2. This is a simple application which demonstrates some of the basics, and a little more advanced
  3. features of using the new Speech Recognition Manager version 1.5.
  4.  
  5. Because version 1.5 is only for PowerPC, this sample is only for PowerPC.
  6.  
  7. One of the things this sample tries to show is a little of the flexibility of the creation of
  8. phrases that the Mac will listen for.
  9.  
  10. To make a flexible formatted language that I could build a Speech Manager language model from I
  11. decided to make my own custom resource type (and template).  I call this the LANG resource.
  12. Basically all it does is specify what you can say, and what to do when you say what you said.
  13.  
  14. The nice thing about these resources means that I can change them and then re-run the app, I
  15. don't have to use any other application to compile a language model.  The bad part is that the
  16. language model is simpler (therefore a little more cumbersome and less powerfull), a good
  17. tradeoff I think.
  18.  
  19. The 'LANG' resource is a way of specifying a simple BNF language.  Let me attempt to explain
  20. how it works.
  21.  
  22. 1)    'LANG' 128 is read in, this resource must exist.
  23. 2)    The "Only sub path" flag is checked and if it is non-zero the entire resource is skipped
  24.     (because sub paths will be read at another time).
  25. 3)    The first entry of the 'LANG' resource is read and its flags are checked.
  26. 3a)    If the flags are all zero then the word is its own path (it's a complete phrase by itself)
  27.     and the "Type" and "ID" fields say what to do if this phrase is recognized.
  28. 3b)    If the flags == 1 then the word is the first part of phrase and the "Type" and "ID" fields
  29.     specify the resource to read to get next phrase in the phrase which is being built up.
  30. 4)    The "Phrase" field is read and is installed as a word for the Mac to listen for.
  31. 5)    The above steps are repeated until every 'LANG' entry in the current resource has been
  32.     entered into the current language.
  33. 6)    The next 'LANG' resource is processed into its own language until there are no more 'LANG'
  34.     resources left to process.
  35.  
  36. An example seems to be in order...  OK, let's take a simple case, 'LANG' 128, the first entry
  37. is:
  38.  
  39. Flags  $00000000
  40. Type   LANG
  41. ID     129
  42. Phrase Video
  43.  
  44. When the computer recognizes "Video" the program will call the routine which dispatches actions
  45. with 'LANG' and 129 as arguments.  This will cause the program to switch to the language which
  46. was built from 'LANG' resource #129.  Simple, right?
  47.  
  48. So let's look at 'LANG' 129.  We see that it's fourth entry has its Flags set to 1, which means
  49. that the Phrase is the beginning of the phrase to be listened for.  Its Type and ID specify
  50. 'LANG' 142 for the rest of the phrases, so we look there and we find that the three entries are
  51. classified as being "Only sub path" which means that saying these words by themselves means
  52. nothing.
  53.  
  54. So, if the user were to say "Video" the computer is now listening for the various video
  55. commands, one of which is volume XXXXX where XXXXX is either mute, down, or up.  So you can say
  56. "volume up", or "volume mute", or "volume down".  Once you say "volume up" the dispatch
  57. routine is called with arguments of 'vol ' and 2 which it knows means to turn up the volume.
  58.  
  59. There are a few commands which are built from three different phrases.  You can build quite
  60. complicated languages using just this simple model, and this is only a fraction of the
  61. capability of the Speech Recognition Manager.
  62.  
  63. You should look through the 'LANG' resources to get a feel for what you can say, or just throw
  64. them away and create your own language.
  65.  
  66. This example was built around the idea of home automation, but most of the commands do nothing
  67. but beep back at you (signaling they were carried out), since I haven't got around to getting
  68. the home automation hardware...
  69.  
  70. I have used this framework to add functions to a few simple applications.  I hope you find it
  71. usefull as well.
  72.  
  73. I believe that this code works just fine, sometimes it goes to the wrong places in the language
  74. tree, but so far that has been because it mis-understood me.  Probably a poor choice of words
  75. on my part.  Sometimes it just doesn't understand me, again this probably a poor choice of words
  76. on my part.
  77.  
  78. If you find any real bugs (not understanding you, or hearing the wrong word isn't something
  79. I can fix), please let me know.
  80.  
  81. Mark Cookson, mcookson@apple.com
  82. Developer Technical Support
  83. Apple Computer, Inc.
  84. */